﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Earworm.Web.DBM;

namespace Earworm.Web.Registration
{
    public partial class Login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnLogin_Click(object sender, EventArgs e)
        {
            CustomValidator val = new CustomValidator();
            string err = "";
            EarwormDataContext ear = new EarwormDataContext();
            var i = ear.TestLogin(txtPassword.Text, txtEmail.Text, ref err);

            if (i.ReturnValue.ToString() == "1")
            {
                Session["userEmail"] = txtEmail.Text;
                Response.Redirect("~/Users/Account.aspx");
            }
            else
            {
                val.IsValid = false;
                val.ErrorMessage = err;
                this.Page.Validators.Add(val);
                txtPassword.Text = "";
            }


        }
    }
}